import requests
import openpyxl
import re
from decimal import Decimal

url='http://calculator.webapp.163.com/xyq_mnjd_gj/mnjdgjs?callback=jQuery1640018944610373485604_1632617639659&zz='
tm1='&gj0='
tm2='&czl='
tm3='&lv='
tm4='&_=1632619393826'


# zizhi='1500'
# liliang='129'
# chengzhang='1264'
# level='119'
# html = requests.get(url+zizhi+tm1+liliang+tm2+chengzhang+tm3+level+tm4)
# print(html.text)

base_url='http://calculator.webapp.163.com/xyq_mnjd_gj/mnjdgjs?callback=jQuery1640018944610373485604_1632617639659&zz={}&gj0={}&czl={}&lv={}&_=1632619393826'

workbook = openpyxl.load_workbook('tmp.xlsx')

sheet = workbook["test"]
# 获取最大列数
maxColumn = sheet.max_column
print('最大列', maxColumn)
max_row = sheet.max_row
print('最大行', max_row)

cout=0

def ttt():
    global cout

    for one_column_data in sheet.iter_rows():
        if cout == 0:
            cout = cout + 1
            continue

        zizhi = one_column_data[3].value
        liliang = one_column_data[2].value
        chengzhang = one_column_data[0].value
        level = one_column_data[1].value
        full_url=base_url.format(zizhi, liliang, chengzhang, level)
        html = requests.get(full_url)
        #print(full_url)
        s = re.findall("\d+", html.text)[0]
        gongji=(Decimal(chengzhang)*Decimal(liliang)/Decimal(1000))+(Decimal(zizhi)*Decimal(level)*Decimal(3.2)/Decimal(1000))
        chazhi=int(s)-gongji
        print('自算: {} === 官方 : {} =====差值: {}'.format(gongji.__str__(),s,chazhi.__str__()))




ttt()


    #html = requests.get(url+zizhi+tm1+liliang+tm2+chengzhang+tm3+level+tm4)
    #print(html.text)
